<?php

// Get options
$fazio_options = get_option('fazio_options');

// Define default options
$fazio_options_def = array(
	'layout_use_thumbnails' => 'on',
	'layout_full_post' => 'off',
	'layout_show_excerpt' => 'on',
	'layout_sidebar_on_home' => 'on',
	'layout_sidebar_on_single' => 'on',
	'slider_status' => 'off',
	'slider_tag_name' => 'featured',
	'slider_limit' => '5',
	'slider_show_excerpt' => 'off',
	'slider_effect' => '',
	'slider_delay' => '3000',
	'slider_width' => '940',
	'slider_height' => '300',
	'slider_opacity' => '0.7',
	'slider_title_speed' => '500',
	'slider_pause_on_hover' => 'on'
);
	
// Generate array options
function fazio_generate_options()
{
	global $fazio_options, $fazio_options_def;
	
	$fazio_options = get_option('fazio_options');
	
	// Combine
	foreach($fazio_options_def as $key => $val)
	{
		if(!isset($fazio_options[$key]))
		{
			$fazio_options[$key] = $val;
		}
	}
}

fazio_generate_options();

// Get option
function fazio_option($key)
{
	global $fazio_options;
	
	return $fazio_options[$key];
}

// Get default option
function fazio_option_def($key)
{
	global $fazio_options_def;
	
	return $fazio_options_def[$key];
}

// Initiate options class. Set Fazio settings.
require('class/options_class.php');
$d = new Options('fazio_options');

// Sections
$d->sections['layout'] = array(
	'id'			=> 'layout',
	'name'			=> __('Layout', 'fazio'),
	'description'	=> __('Configure layout settings here', 'fazio'),
);

$d->sections['slider'] = array(
	'id'			=> 'slider',
	'name'			=> __('Featured Posts Slider (CoinSlider)', 'fazio'),
	'description'	=> __('Configure your slider settings', 'fazio'),
);

// Layout: Use Thumbnail?
$d->options['layout'][] = array(
	'id'			=> 'layout_use_thumbnails',
	'name'			=> __('Show Post Thumbnails', 'fazio'),
	'description'	=> __('Check this if you want to use post thumbnails.', 'fazio'),
	'type'			=> 'checkbox',
	'value'			=> fazio_option('layout_use_thumbnails'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('layout_use_thumbnails')
);

// Layout: Full content
$d->options['layout'][] = array(
	'id'			=> 'layout_full_post',
	'name'			=> __('Show full post', 'fazio'),
	'description'	=> __('Check this if you want to show the full post on the blog index (Until <span style="font-weight: bold; font-style: italic;">&lt;!-- more --&gt;</span> tag).', 'fazio'),
	'type'			=> 'checkbox',
	'value'			=> fazio_option('layout_full_post'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('layout_full_post')
);

// Layout: Show excerpt
$d->options['layout'][] = array(
	'id'			=> 'layout_show_excerpt',
	'name'			=> __('Show excerpt on posts', 'fazio'),
	'description'	=> __('Check this if you want to show the excerpt.', 'fazio'),
	'type'			=> 'checkbox',
	'value'			=> fazio_option('layout_show_excerpt'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('layout_show_excerpt')
);

// Layout: Show sidebar on home?
$d->options['layout'][] = array(
	'id'			=> 'layout_sidebar_on_home',
	'name'			=> __('Show sidebar on home', 'fazio'),
	'description'	=> __('Check this if you want to show the sidebar in the home.', 'fazio'),
	'type'			=> 'checkbox',
	'value'			=> fazio_option('layout_sidebar_on_home'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('layout_sidebar_on_home')
);

// Layout: Show sidebar on single?
$d->options['layout'][] = array(
	'id'			=> 'layout_sidebar_on_single',
	'name'			=> __('Show sidebar on single', 'fazio'),
	'description'	=> __('Check this if you want to show the sidebar when seeing a post.', 'fazio'),
	'type'			=> 'checkbox',
	'value'			=> fazio_option('layout_sidebar_on_single'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('layout_sidebar_on_single')
);

// Slider: Status
$d->options['slider'][] = array(
	'id'			=> 'slider_status',
	'name'			=> __('Slider status', 'fazio'),
	'description'	=> __('Check if you want to activate the featured posts slider', 'fazio'),
	'type'			=> 'checkbox',
	'value'			=> fazio_option('slider_status'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('slider_status')
);

// Slider: Tag name
$d->options['slider'][] = array(
	'id'			=> 'slider_tag_name',
	'name'			=> __('Tag Name', 'fazio'),
	'description'	=> __('The tag which Fazio will use to detect featured posts', 'fazio'),
	'type'			=> 'text',
	'value'			=> fazio_option('slider_tag_name'),
	'required'		=> 'required',
	'validate'		=> 'trim',
	'default'		=> fazio_option_def('slider_tag_name')
);

// Slider: Quantity limit
$d->options['slider'][] = array(
	'id'			=> 'slider_limit',
	'name'			=> __('Quantity Limit', 'fazio'),
	'description'	=> __('The max quantity of posts which will be selected.', 'fazio'),
	'type'			=> 'text',
	'value'			=> fazio_option('slider_limit'),
	'required'		=> 'required',
	'validate'		=> 'intval',
	'default'		=> fazio_option_def('slider_limit')
);

// Slider: Show excerpt
$d->options['slider'][] = array(
	'id'			=> 'slider_show_excerpt',
	'name'			=> __('Show excerpt?', 'fazio'),
	'description'	=> __('Check if you want to show the excerpt below the title', 'fazio'),
	'type'			=> 'checkbox',
	'value'			=> fazio_option('slider_show_excerpt'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('slider_show_excerpt')
);

// Slider: Animation effect
$d->options['slider'][] = array(
	'id'			=> 'slider_effect',
	'name'			=> __('Animation: Effect', 'fazio'),
	'description'	=> __('The effect which will be used in the slider', 'fazio'),
	'type'			=> 'select',
	'options'		=> array(
			''			=> 'Default',
			'swirl'		=> 'Swirl',
			'rain'		=> 'Rain',
			'straight'	=> 'Straight'
	),
	'value'			=> fazio_option('slider_effect'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('slider_effect')
);

// Slider: Animation delay
$d->options['slider'][] = array(
	'id'			=> 'slider_delay',
	'name'			=> __('Animation: Delay', 'fazio'),
	'description'	=> __('Time between posts. In milliseconds.', 'fazio'),
	'type'			=> 'text',
	'value'			=> fazio_option('slider_delay'),
	'required'		=> 'required',
	'validate'		=> 'intval',
	'default'		=> fazio_option_def('slider_delay')
);

// Slider: Animation title speed
$d->options['slider'][] = array(
	'id'			=> 'slider_title_speed',
	'name'			=> __('Animation: Title speed', 'fazio'),
	'description'	=> __('Speed of title appareance. In milliseconds.', 'fazio'),
	'type'			=> 'text',
	'value'			=> fazio_option('slider_title_speed'),
	'required'		=> 'required',
	'validate'		=> 'intval',
	'default'		=> fazio_option_def('slider_title_speed')
);

// Slider: Title opacity
$d->options['slider'][] = array(
	'id'			=> 'slider_opacity',
	'name'			=> __('Title opacity', 'fazio'),
	'description'	=> __('The opacity of the title (and excerpt?). From 0.1 to 1.0. Default: 0.7.', 'fazio'),
	'type'			=> 'text',
	'value'			=> fazio_option('slider_opacity'),
	'required'		=> 'required',
	'validate'		=> 'floatval',
	'default'		=> fazio_option_def('slider_opacity')
);

// Slider: Width
$d->options['slider'][] = array(
	'id'			=> 'slider_width',
	'name'			=> __('Slider width', 'fazio'),
	'description'	=> __('The width of the slider. In pixels.', 'fazio'),
	'type'			=> 'text',
	'value'			=> fazio_option('slider_width'),
	'required'		=> 'required',
	'validate'		=> 'intval',
	'default'		=> fazio_option_def('slider_width')
);

// Slider: Height
$d->options['slider'][] = array(
	'id'			=> 'slider_height',
	'name'			=> __('Slider height', 'fazio'),
	'description'	=> __('The height of the slider. In pixels.', 'fazio'),
	'type'			=> 'text',
	'value'			=> fazio_option('slider_height'),
	'required'		=> 'required',
	'validate'		=> 'intval',
	'default'		=> fazio_option_def('slider_height')
);


// Slider: Pause on hover
$d->options['slider'][] = array(
	'id'			=> 'slider_pause_on_hover',
	'name'			=> __('Pause slider on hover?', 'fazio'),
	'description'	=> __('Check if you want to stop the slider on mouse over.', 'fazio'),
	'type'			=> 'checkbox',
	'value'			=> fazio_option('slider_pause_on_hover'),
	'required'		=> 'required',
	'default'		=> fazio_option_def('slider_pause_on_hover')
);

$d->check_update();

// Create page under Appeareance
add_action('admin_menu', 'fazio_admin_menu');
function fazio_admin_menu()
{
	// $page_title, $menu_title, $capability, $menu_slug, $function
	add_theme_page('Fazio Theme Options', 'Fazio Options', 'edit_theme_options', 'fazio', 'fazio_display_options');
}

function fazio_display_options()
{
	global $d;
?>
	<style type="text/css">
		.wrap input, .wrap select, .wrap textarea {
			width: 300px;
			padding: 3px;
		}
		
		.wrap textarea {
			height: 100px;
		}
		
		.wrap textarea:focus {
			height: 200px;
		}
		
		.wrap input[type=checkbox]
		{
			width: 15px;
		}
		
		.wrap input[type=submit]
		{
			width: auto;
			padding: 5px 10px;
		}
		
		.wrap h3 {
			margin-top:30px;
		}
	</style>
	
	<div class="wrap">
		<div id="icon-edit-pages" class="icon32"><br /></div> 
		<h2><?php _e('Fazio Theme Options', 'fazio'); ?></h2>
		
		<?php if(isset($_GET['saved'])) : ?>
			<div id="setting-error-settings_updated" class="updated settings-error"> 
				<p>
					<strong>Settings saved.</strong>
				</p>
			</div>
		<?php endif; ?>
		
		<p><?php _e('Hi! Welcome to Fazio Options Page.<br />
		If you need any help, send me an email to: <a href="mailto:master@teleportz.com.ar">master@teleportz.com.ar</a> or contact me in <a href="http://twitter.com/santiagodi">Twitter &raquo; santiagodi</a>.', 'fazio'); ?></p>
		
		<form action="themes.php?page=fazio" method="post">
			<input type="hidden" name="save" value="true" />
			<?php echo $d->prepare(); ?>
			<p><input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" /></p>
		</form>
		
	</div>
<?php
}